<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
	String cpath = request.getContextPath();
	request.setAttribute("cpath", cpath);
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="CACHE-CONTROL" CONTENT="NO-CACHE" />
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE" />
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<script type="text/javascript">
	var cxpath = '${cxpath}';
</script>
<script src="${cpath}/js/jquery-2.1.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${cpath}/js/action/actionUtils.js"></script>
<script type="text/javascript" src="${cpath}/js/action/userManage.js"></script>
<link rel="stylesheet" href="${cpath}/css/bootstrap-2.3.2.min.css" media="all" type="text/css" />
<link rel="stylesheet" href="${cpath}/css/freechat.css" media="all" type="text/css" />
<script src="${cpath}/js/bootstrap-3.3.6.min.js" type="text/javascript"></script>
<title>FreeChat</title>
</head>
<body>
	<div id="main_wrapper">
		<div class="overlay"></div>
		<div id="loading">
			<div id="loading_logo">FreeChat</div>
			<div id="loading-title"> Loading... </div>
		</div>
		<div class="row-fluid" id="intro">
			<div id="intro-image">
				<div id="intro-header" class="clearfix">
					<div id="login-form">
						<div id="login-button-wrapper">
							<a href="#" id="login-button-temp">登录</a>
						</div>
						<div id="login-form-wrapper">
							<input type="text" class="login-field login-email" value="" placeholder="邮箱/用户名" id="intro-login-email"  />
							<input type="password" class="login-field login-password" id="intro-login-password" value="" placeholder="密码" />
						</div>
					</div>
				</div>
				<div id="intro-top">
					<div class="logo-intro">FreeChat</div>
				</div>
				<div id="start-chatting-now-wrapper">
					<a href="#" id="start-chatting-temp">现在开始聊天!</a>
				</div>
				<div id="intro-descrip-wrapper" class="clearfix">
					<div class="intro-top-elem">
						<div id="intro-top-left-image" class="intro-top-image"></div>
						<span class="intro-top-text">在FreeChat社区结识新朋友，谈论你关心的事情！</span>
					</div>
					<div class="intro-top-elem">
						<div id="intro-top-right-image" class="intro-top-image"></div>
						<span class="intro-top-text">与完全随机的人聊天或与跟你有相同兴趣爱好的朋友聊天</span>
					</div>
				</div>
			</div>
		</div>	
	</div>
	<script>
		function login() {
			var login_form = $('#login-form-wrapper');
			if (login_form.css("opacity") == 0) {
				login_form.css("display", "inline-block");
				login_form.animate({
					"left": "-10px",
					"opacity": "1"
				});
				return;
			}
			var login_email = login_form.find('#intro-login-email');
			var login_pswd = login_form.find('#intro-login-password');
			var flag = true;
			if (login_email.val().length == 0) {
				errorInfo(login_email, "请输入用户名或邮箱");
				flag = false;
			}
			if (login_pswd.val().length == 0) {
				errorInfo(login_pswd, "请输入密码");
				flag = false;
			}
			if (!flag)
				return;
			userManage.login(login_email.val(), login_pswd.val(), function(data) {
				if (data == 1) {
					errorInfo(login_email, "用户名不存在");
					login_email.val('');
				} else if (data == 2) {
					errorInfo(login_pswd, "密码错误");
					login_pswd.val('');
				} else {
					location.reload();
				}
			});
		}
	
		$('#login-button-temp').click(login);
		
		function errorInfo(field, error) {
			field.addClass('red');
			field.attr("placeholder", error);

		}
		
		$('#start-chatting-temp').click(function() {
			$('#intro').hide();
			userManage.login(null, null, function(data) {
				location.reload();
			});
		});
		
		$(function() {
			$(document).keydown(function(event) {
				if (event.which == 13) {
					login();
				}
			});
			var loginWay = '${loginWay}';
			//var loginWay = getCookie('loginWay');
			console.log(loginWay);
			if (loginWay == '1') {
				$('#start-chatting-temp').click();
			}
		});
		
		
		function getCookie(c_name) {
			if (document.cookie.length > 0) {
				c_start = document.cookie.indexOf(c_name + "=")
				if (c_start != -1) {
					c_start = c_start + c_name.length + 1
					c_end = document.cookie.indexOf(";", c_start)
					if (c_end == -1)
						c_end = document.cookie.length
					return unescape(document.cookie.substring(c_start, c_end))
				}
			}
			return "";
		}
	</script>
</body>
</html>